﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Framework.Message.SMS.CommonLibrary.Generic
{
    public abstract class BaseCommandHeader<CommandT, SequenceT>
    {
        #region 变量与属性
        /// <summary>
        /// 
        /// </summary>
        public abstract uint CommandHeaderLength { get; }

        private uint _MessageLength = 0;
        /// <summary>
        /// 消息的总长度(字节)
        /// </summary>
        public uint MessageLength
        {
            get { return _MessageLength; }
            set { _MessageLength = value; }
        }

        protected CommandT _CommandID;
        /// <summary>
        /// 命令ID
        /// </summary>
        public CommandT CommandID
        {
            get { return _CommandID; }
        }

        private SequenceT _SequenceNumber;
        /// <summary>
        /// 序列号
        /// </summary>
        public SequenceT SequenceNumber
        {
            get { return _SequenceNumber; }
            set { _SequenceNumber = value; }
        }
        #endregion

        public BaseCommandHeader(CommandT commandID, uint bodyLength, SequenceT sequence)
        {
            this._CommandID = commandID;
            this._SequenceNumber = sequence;
            this._MessageLength = bodyLength + CommandHeaderLength;
        }

        public BaseCommandHeader(byte[] bytes)
        {
            ByteTo(bytes, 0);
        }

        public BaseCommandHeader(byte[] bytes, int startIndex)
        {
            ByteTo(bytes, startIndex);
        }

        protected abstract void ByteTo(byte[] bytes, int startIndex);

        public abstract byte[] ToBytes();
    }
}
